package com.sline.Socket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class Demo2_Send {
    public static void main(String[] args) throws IOException {
        String str = "what are you 弄啥呢";

        // 创建键盘录入对象
        Scanner sc = new Scanner(System.in);
        // 创建socket
        DatagramSocket socket = new DatagramSocket();

        while (true) {
            String line = sc.nextLine();

            if ("quit".equals(line)) {
                break;
            } else {
                // 创建packet
                DatagramPacket packet = new DatagramPacket(line.getBytes(), line.getBytes().length, InetAddress.getByName("127.0.0.1"), 6666);
                // 将数据发出去
                socket.send(packet);
            }
        }

        // 关闭码头
        socket.close();


    }
}
